<template>
	<!-- 商品显示 组件 -->
	<view class="goodsComponent">
		<view :style="{
	        backgroundColor: newData.background
	          ? newData.background.indexOf('bg-') !== -1
	            ? ''
	            : newData.background
	          : newData.background,
	        paddingTop: `${newData.pageUpSpacing}rpx`,
	        paddingBottom: `${newData.pageDownSpacing}rpx`,
	        paddingLeft: `${newData.pagelrSpacing}rpx`,
	        paddingRight: `${newData.pagelrSpacing}rpx`,
	      }" :class="
	        newData.background
	          ? newData.background.indexOf('bg-') !== -1
	            ? newData.background
	            : ''
	          : 'bg-' + thememobile.backgroundColor
	      ">
			<view class="goods-container flex">
				<view class="f-goods-box" v-for="(item, index) in goodsList" :key="index">
					<navigator class="goods-box1" :url="'/pages/goods/goods-detail/index?id=' + item.spuId+ '&activityId=' + item.activityId">
						<view style="position: relative;">
							<view class="img-box">
								<view class="" style="position: relative;height: 100%;" v-if="item.prescription=='2'">
									<view class="flex flex-column-center"
										style="position: absolute;width: 100%;height:100%;z-index: 50;align-items: center;color: #666666">
										<view class="" style="font-size: 24rpx;">处方药依法不展示包装</view>
										<view class="" style="font-size: 24rpx;">请在药师指导下使用</view>
									</view>								
									<image :src="item.picUrls && item.picUrls[0] ? item.picUrls[0] : noPic" mode="scaleToFill"
										class="card-img" style="filter: blur(5rpx);"/>
								</view>
								<image :src="item.picUrls && item.picUrls[0] ? item.picUrls[0] : noPic" mode="scaleToFill"
									class="card-img" v-if="item.prescription!='2'"/>
							</view>
							<!-- #ifdef MP-WEIXIN -->
							<view class="text-black margin-top-xs overflow-2"
								style="padding: 0 20rpx;font-weight: 700;height: 64rpx;font-size: 22rpx;">
								{{ item.spuName }}
							</view>
							<!-- #endif -->
							<!-- #ifdef MP-ALIPAY -->
							<view class="text-black margin-top-xs overflow-2"
								style="padding: 0 20rpx;font-weight: 700;height: 56rpx;font-size: 22rpx;">
								{{ item.spuName }}
							</view>
							<!-- #endif -->
							<view class="margin-top-sm" style="padding: 0 20rpx">
								<view class="flex justify-between align-center margin-top-sm">
									<view class="text-price text-bold text-red text-lg row-price">
										{{ item.price }}
									</view>
									<image src="https://fs-mix.oss-cn-beijing.aliyuncs.com/1/material/25d17b7a-eb89-49cd-bc63-64954b1214a1.png"
										alt="" style="height: 40rpx; width: 40rpx" />
								</view>
								<view>
									<view class="text-price text-gray row-price"
										style="font-size: 20rpx; text-decoration: line-through"
										v-if="parseFloat(item.oldPrice) > parseFloat(item.price)">
										{{ item.oldPrice }}
									</view>
									<view class="text-price text-gray row-price text-white"	style="font-size: 20rpx;" v-else>
									</view>
								</view>
							</view>
							<view class="cfBox" v-if="item.prescription == '2'">处方药</view>
							<view class="preBox" v-if="item.isPressell==1">
								预约
							</view>
						</view>
					</navigator>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	const app = getApp();
	import api from '@/utils/api'

	export default {
		props: {
			value: {
				type: Object,
				default: function() {
					return {
						showType: 'row',
						pageSpacing: 0,
						goodsList: []
					}
				}
			},
			activityId: {},
		},
		data() {
			return {
				theme: app.globalData.theme, //全局颜色变量
				newData: this.value,
				goodsList: []
			};
		},
		mounted() {
			this.getgoodsList()
		},
		methods: {
			jumpPage(page) {
				if (page) {
					uni.navigateTo({
						url: page
					});
				}
			},
			// 获取活动商品
			getgoodsList() {
				if (this.value.goodsList && this.value.goodsList.length > 0) {
					let goodsids = []
					this.value.goodsList.forEach(v => {
						goodsids.push(v.spuId)
					})
					const page = {
						activityId: this.activityId,
						goodsids: goodsids.toString(),
					}
					// 分类权限
					const UrlParams = uni.getStorageSync('UrlParams')
					if (UrlParams && UrlParams.mark) {
						page.mark = UrlParams.mark
					}
					api.getActiveGoodByid(page).then(res => {
						let data = res.data
						if (data.length > 0) {
							this.goodsList = data.filter(v => {
								return v.status == 1
							})
						} else {
							this.goodsList = []
						}

					})
				}

			}
		}
	}
</script>

<style scoped>
	.goodsComponent {
		position: relative;
		display: block;
		width: 100%;
	}

	.card-img {
		width: 100% !important;
		height: 100% !important;
		border-radius: 10rpx;
	}

	.goods-container {
		flex-wrap: wrap;
		box-sizing: content-box;
	}

	.f-goods-box {
		width: 33.33%;
		padding: 0 4rpx;
		margin: 5rpx 0;
	}

	.goods-box1 {
		background-color: #fff;
		overflow: hidden;
		border-radius: 10rpx;
		width: 100%;
		height: 100%;
	}

	.goods-box1 .img-box {
		width: 100%;
		height: 220rpx;
		overflow: hidden;
	}

	.goods-box1 .img-box image {
		width: 100%;
		height: 520rpx;
	}

	.overflow-1 {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.overflow-2 {
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}	
	
	.cfBox {
		width: 100rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
		background-color: #00a6ba;
		position: absolute;
		left: 0;
		top: 0;
		color: white;
		border-radius: 10rpx;
	}
	
	.preBox {
		width: 240rpx;
		height: 40rpx;
		line-height: 40rpx;
		text-align: center;
		background-color: #F76164;
		position: absolute;
		left: 0;
		top: 180rpx;
		color: white;
		opacity: 0.8;
		margin-left: 1rpx;
	}
</style>
